<script>
import { verify_home } from "@/utils/public";

export default {
  onLaunch: function() {},
  onShow(option) {
    // onShow 方法中判断是否有更新
    const updateManager = uni.getUpdateManager();
    updateManager.onCheckForUpdate(res => {
      // 请求完新版本信息的回调
      if (res.hasUpdate) {
        updateManager.onUpdateReady(res => {
          uni.showModal({
            title: "更新提示",
            content: "新版本已经准备好，是否重启应用？",
            success: res => {
              if (res.confirm) {
                // 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
                updateManager.applyUpdate();
              }
            }
          });
        });
      }
    });
    updateManager.onUpdateFailed(res => {
      // 新的版本下载失败
      uni.showModal({
        title: "提示",
        content: "检查到有新版本，但下载失败，\n请检查网络设置",
        success(res) {
          if (res.confirm) {
            // 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
            updateManager.applyUpdate();
          }
        }
      });
    });

    if (
      option.path === "payroll/paydetail" ||
      option.path === "contract/preview" ||
      option.path === "notification/detail" ||
      option.path === "announcement/detail" ||
      option.path === "fxdj/index" ||
      option.path === "pages/reg/index"
    ) {
      let data = {
        url: `/${option.path}`,
        query: option.query
      };
      uni.setStorageSync("redirectUrl", JSON.stringify(data));
    } else {
      uni.setStorageSync("redirectUrl", "");
    }
    if (
      option.path !== "pages/reg/index" &&
      option.path !== "pages/index/index" &&
      option.path !== "entryAll/manualAdd/manualAdd" &&
      option.path !== "pages/index/flashpage" &&
      option.path !== "authorize/login" &&
      option.path !== "fxdj/index"
    ) {
      verify_home()
        .then(() => {})
        .catch(() => {
          uni.navigateTo({
            url: `/authorize/index`
          });
        });
    }

    console.log(option, "option")
    if (option.scene === 1038 && option.referrerInfo && option.referrerInfo.appId === 'wxd24d9057cd83d47a') {
      const resp = option.referrerInfo.extraData || {};
      if (resp.msg_type === 'AUTHENTICATE_WITH_AUTHORIZATION' && resp.authenticate_state === 'AUTHENTICATE_SUCCESS') {
        const wgkJump = uni.getStorageSync('wgkJump')
        if (wgkJump) {
          uni.navigateTo({
            url: '/fxdj/index'
          })
        }
        const wgkJumpFromMine = uni.getStorageSync('wgkJumpFromMine')
        if (wgkJumpFromMine) {
          console.log("wgkJumpFromMine");
        }
    //     // 以下代码根据具体业务修改
    //     const contractId = uni.getStorageSync('contractIdP')
    //     uni.navigateTo({
    //       url: `/contract/sign_doing?id=${contractId}`,
    //     });
    //     // const status = uni.getStorageSync('contractStatusP')
    //     // uni.navigateTo({
    //     //   url:  "/contract/preview?contractId=" + contractId + "&status=" + status
    //     // });
      }
    }
    // uni.hideLoading();
    try {
      const res = uni.getStorageInfoSync();
    } catch (err) {
      console.log("debug log --> ", err);
    }
  }
};
</script>

<style lang="scss">
/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
@import "uview-ui/index.scss";
@import "./styles/index.scss";
page {
  width: 100%;
  height: 100%;
  display: flex;
}
</style>
